<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script src="ajax.js"></script>
		<script>
			onload = function(){
				
				/*
				 登录（POST）
					登录接口:  http://60.205.181.47/myPHPCode3/login.php
					参数:username=zhangsan,用户名
					参数:password=123456,密码
				*/
				
				var aInput = document.getElementsByTagName("input");
				
				//登录
				aInput[2].onclick = function(){
					
					var xhr = createXHR();
					xhr.open("POST", "http://60.205.181.47/myPHPCode3/login.php", true);
					xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					xhr.send("username="+ aInput[0].value + "&password=" + aInput[1].value);
					xhr.onreadystatechange = function(){
						if (xhr.readyState==4 && xhr.status==200) {
							//console.log(xhr.responseText);
							var obj = JSON.parse(xhr.responseText);
							
							//登录成功
							if (obj.status == 1) {
								alert("登录成功！");
							}
							//登录失败
							else {
								alert("登录失败");
							}
						}
					}
					//app
				}
				
			}
		</script>
	</head>
	<body>
		<h2>登录</h2>
		<input type="text" placeholder="用户名"/> <br />
		<input type="password" placeholder="密码"/> <br />
		<input type="button" value="登录"/> 
	</body>
</html>
